package com.v1.video.view.danmaku;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.v1.video.domain.SecondEntity.CommentList;

public class DanmakuHelper {
	private Context mContext;
	private LinearLayout mView;
	private BarrageView mDanmakuView;

	public DanmakuHelper(Context context, LinearLayout view) {
		mContext = context;
		mView = view;
		initView();
	}

	private void initView() {
		mView.removeAllViews();
		mDanmakuView = new BarrageView(mContext);
		mDanmakuView.setLayoutParams(new LinearLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		mView.addView(mDanmakuView);
	}

	public void addItem(List<CommentList> lstData) {
		if (lstData != null && lstData.size() > 0) {
			Deque<String> deque = new LinkedList<String>();
			for (int i = 0; i < lstData.size(); i++) {
				String content = lstData.get(i).getContent();
				if (!TextUtils.isEmpty(content)) {
					deque.add(content);
				}
			}
			if (mDanmakuView != null) {
				mDanmakuView.setLstData(deque);
			}
		}
	}

	public void removeAllViews() {
		if (mView != null) {
			mView.removeAllViews();
		}
	}

	public void start() {
		if (mDanmakuView != null) {
			mDanmakuView.start();
		}
	}

	public void stop() {
		if (mDanmakuView != null) {
			mDanmakuView.stop();
		}
	}
}
